package com.hibuy.pc.common;

import com.google.gson.Gson;
import org.springframework.http.HttpStatus;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
 * @author naicha
 * Created on 2017/11/7.
 */
public class CommonFunction {

    /**
     * 响应数据流
     * @param response
     * @param result
     */
    public static void responseWrite(HttpServletResponse response,Object result){
        Gson gson = new Gson();
        try {
            response.setContentType("application/json;charset=UTF-8");
            response.setStatus(HttpStatus.OK.value());
            response.setHeader("Access-Control-Allow-Origin", "*");
            response.getWriter().write(gson.toJson(result));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
